'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-10-15 11:31:27
'''

'''
type-value与具体type的对应关系：
INT(1, "int"),
LONG(2, "long"),
FLOAT(3, "float"),
DOUBLE(4, "double"),
INT_VECTOR(5, "int-vector"),
FLOAT_VECTOR(6, "float-vector"),
LONG_VECTOR(7, "long-vector"),
DOUBLE_VECTOR(8, "double-vector"),
STRING(9,"string"),
WCMP(13, "L1-Code-W2V序列化"),
STRING_STRING_VALUE(14, "kv[key=string,value=string]"),
STRING_FLOAT_VALUE(15, "kv[key=string,value=float]"),
INT_FLOAT_VALUE(16, "kv[key=int,value=float]");
'''


'''
dimension与具体维度的对应关系
BOSS(1, "Boss(老板)"),
GEEK(2, "Geek(牛人)"),
JOB(3, "Job(职位)"),
EXPECT(4, "Expect(期望)"),
BOSS_GEEK(5, "BossGeek(两两)"),
JOB_EXPECT(6, "JobExpect(两两)"),
COMPANY(7, "Company(公司)"),
SALE(8, "Sale(销售)"),
SALE_COMPANY(10, "SaleCompany(两两)"),
PUSH_TEXT(11, "PushText(Push)"),
USER(13, "User(用户)"),
GEEK_JOB(14, "GeekJob(两两)"),
CITY(15, "City(城市)"),
CONTEXT(16, "Context(上下文)"),
'''

import pymysql
import json
final = []
conn = pymysql.connect(
    host = "172.19.8.66",
    port = 3306,
    user = "algorithm",
    password = "S4!4Eywru@aH",
    # database = "rcd_phoenix_admin",
    database = "rcd_kraken",
    charset='utf8'
    )

cursor = conn.cursor()
sql='show tables'

cursor.execute(sql)
result = list(cursor.fetchall())
all_table_names = []
for i, in result:
    all_table_names.append(i)

# feature_meta  
# feature_namespace_config
# feature_namespace_mapping_config
# feature_storage_config

# name = all_table_names[0]

# sql='desc '+name
# cursor.execute(sql)
# result = list(cursor.fetchall())
# print(result)

# sql = 'select default_value from '+name
# cursor.execute(sql)
# result = (cursor.fetchall())
# print(len(result))

for name in all_table_names:
    print('The table ', name, 'desc')
    sql='desc '+name
    cursor.execute(sql)
    result = list(cursor.fetchall())
    # print(result)
    desc = []
    for i in result:
        desc.append(i[0])
    print(desc)
    sql='select * from '+name
    cursor.execute(sql)
    result = list(cursor.fetchall())
    desc = []
    for i in result[0]:
        desc.append(i)
    print(desc)
